{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-09-07T14:31:47.321110Z",
     "start_time": "2025-09-07T14:31:47.302668Z"
    }
   },
   "source": [
    "# dataframe创建方式\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "# 1.13模块编程. 通过series来创建\n",
    "s1 = pd.Series([1,2,3,4,5])\n",
    "s2 = pd.Series([6,7,8,9,10])\n",
    "df = pd.DataFrame({'第一列':s1,'第二列':s2})\n",
    "#print(df)\n",
    "df"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "   第一列  第二列\n",
       "0    1    6\n",
       "1    2    7\n",
       "2    3    8\n",
       "3    4    9\n",
       "4    5   10"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>第一列</th>\n",
       "      <th>第二列</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 3
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-09-07T14:35:42.543595Z",
     "start_time": "2025-09-07T14:35:42.522056Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 2. 通过字典来创建\n",
    "df = pd.DataFrame(\n",
    "    {\n",
    "        'id':[1,2,3,4,5],\n",
    "        'name':['张三','李四','王五','赵六','小七'],\n",
    "        'age':[18,19,20,21,22],\n",
    "        'score':[60,72.5,83.5,90,100]\n",
    "    }, index=[1,2,3,4,5],columns=['id','name','score','age']\n",
    ")\n",
    "df"
   ],
   "id": "ebab34a5ec271bba",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "   id name  score  age\n",
       "1   1   张三   60.0   18\n",
       "2   2   李四   72.5   19\n",
       "3   3   王五   83.5   20\n",
       "4   4   赵六   90.0   21\n",
       "5   5   小七  100.0   22"
      ],
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>name</th>\n",
       "      <th>score</th>\n",
       "      <th>age</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>张三</td>\n",
       "      <td>60.0</td>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>李四</td>\n",
       "      <td>72.5</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>王五</td>\n",
       "      <td>83.5</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>赵六</td>\n",
       "      <td>90.0</td>\n",
       "      <td>21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>5</td>\n",
       "      <td>小七</td>\n",
       "      <td>100.0</td>\n",
       "      <td>22</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 8
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
